package com.xinqi.modules.prepare.question.dto.rsp;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * 备课区试题汇总信息
 *
 * @author: system
 * @date: 2023/03/19
 */
@Data
@Schema(description = "备课区试题汇总信息")
public class PrepareQuestionStatsDataDTO implements Serializable {
    /**
     * 题目总数量
     */
    @Schema(description = "题目总数量", example = "50")
    private Integer questionTotal;
    /**
     * 题型总数
     */
    @Schema(description = "题型总数", example = "6")
    private Integer typeTotal;
    /**
     * 题目总分数
     */
    @Schema(description = "题目总分数", example = "100")
    private Integer scoreTotal;

    @Schema(description = "备课区试题汇总明细数据")
    private List<QuestionTypeStatsDetail> questionStatsDetailList;

    public static PrepareQuestionStatsDataDTO of(List<QuestionTypeStatsDetail> list) {
        if (list == null) {
            list = Collections.emptyList();
        }
        int questionTotal = 0;
        int scoreTotal = 0;
        for (QuestionTypeStatsDetail questionStatsDetail : list) {
            questionTotal += questionStatsDetail.getQuestionTypeNum();
            scoreTotal += questionStatsDetail.getQuestionTypeScore();
        }
        PrepareQuestionStatsDataDTO dto = new PrepareQuestionStatsDataDTO();
        dto.setQuestionTotal(questionTotal);
        dto.setScoreTotal(scoreTotal);
        dto.setTypeTotal(list.size());
        dto.setQuestionStatsDetailList(list);
        return dto;
    }
}
